<%@page language="java" pageEncoding="UTF-8"%>
<%@page contentType="text/html; charset=utf-8"%>
<%@page import="com.mysql.jdbc.Driver"%>
<%@page import="java.sql.*"%>
<%
request.setCharacterEncoding("UTF-8");

String wname=request.getParameter("wname");
String category=request.getParameter("category");
String picUrl=request.getParameter("pic_url");
String des=request.getParameter("description");

  if(picUrl.indexOf("fakepath")!=-1){
	  picUrl=picUrl.replace("C:\\fakepath\\","");
  }
System.out.println(picUrl);
String userName="root";
String userPassword="";
String dbName="a0713225307";

try{
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	String u="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPassword+"&useUnicode=true&characterEncoding=UTF-8";
	
	java.sql.Connection connection=java.sql.DriverManager.getConnection(u,userName,userPassword);
String sql="insert into mywork_db(wname,category,url,description)values('"+wname+"','"+category+"','../my/"+picUrl+"','"+des+"')";
	Statement statement=connection.createStatement();
	
	if(statement.executeUpdate(sql)==1){
		System.out.println(wname);
		
	}else{
		System.out.println("fail");
	}
	
	if(statement!=null){
		statement.close();
	}
	
	if(connection!=null){
		connection.close();
	}
	}catch(Exception e){
		e.printStackTrace();
		System.out.println(e);
		
	}

%>